var teamService = require('../Service/teamService.js');
var projectService = require('../Service/projectService.js');

exports.member = function (req, res) {
    projectService.get(req.params.ProjectId, function (project) {
        res.render('team', {Project: project});
    });
};
exports.memberInProject = function (req, res) {
    teamService.memberInProject(req.param("ProjectId"), function (data) {
        var result = [];
        for (var i = 0; i < data.length; i++) {
            result.push({Nick: data[i].Nick, Email: data[i].Email, UserId: data[i].UserId});
        }
        res.json(result);
    });
};
exports.memberCandidate = function (req, res) {
    teamService.memberCandidate(req.param("ProjectId"), function (data) {
        var result = [];
        for (var i = 0; i < data.length; i++) {
            result.push({Nick: data[i].Nick, Email: data[i].Email});
        }
        res.json(result);
    });
};
exports.addMember = function (req, res) {
    var projectId = req.param("ProjectId");
    var email = req.param("Email");
    teamService.addMember(projectId, email, function () {
        res.json({Result: "OK"});
    });
};
exports.removeMember = function (req, res) {
    var projectId = req.param("ProjectId");
    var userId = req.param("UserId");
    teamService.removeMember(projectId, userId, function () {
        res.json({Result: "OK"});
    });
};